<?php

declare (strict_types=1);
namespace App\Model;

use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $supervise_id 
 * @property int $sheet_id 
 * @property string $reply_txt 
 * @property string $reply_images 
 * @property int $userable_id 
 * @property string $userable_type 
 * @property int $unit_id 
 * @property string $unit_name 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property string $deleted_at 
 */
class SuperviseSheetReply extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'supervise_sheet_reply';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'supervise_id',
        'sheet_id',
        'reply_txt',
        'reply_images',
        'userable_id',
        'userable_type',
        'unit_id',
        'unit_name'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'int', 'supervise_id' => 'integer', 'sheet_id' => 'integer', 'userable_id' => 'integer', 'unit_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function getReplyImagesAttribute($field){
        if($field){
            $image_arr = explode(',',$field);
            foreach ($image_arr as &$image){
                preg_match("/(?:[http|https]:\/\/)([^\/]+)/", $image, $matched);
                if(empty($matched)){
                    $image = env('QINBIU_DOMAIN').$image;
                }
            }
            return $this->attributes[$field]=$image_arr;
        }
        return $this->attributes[$field] = null;
    }

}